import pymysql

conn = pymysql.connect(host='127.0.0.1', port=3306,
                       user='root', password='123456',
                       database='hrs', charset='utf8mb4')
try:
    with conn.cursor() as cursor:
        cursor.execute('select `dno`,`dname`,`dloc` from `tb_dept`')
        row = cursor.fetchone()
        while row:
            print(row)
            row = cursor.fetchone()
except pymysql.MySQLError as err:
    print(type(err),err)
finally:
    conn.close()

